package cn.com.citydo.base.query;


import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class QueryPage {

	private Integer page=1;
	
	private Integer pageSize = 10;
	
	private Integer firstResult;

	private Map<String,Object> condition = new HashMap<>(); //查询条件  key为字段   前端传参为 p_字段

	private Map<String,String> searchCondition = new HashMap<>();  //模糊查询条件  key为字段   前端传参为 s_字段

	private Map<String,Object> rangeCondition = new HashMap<>(); //范围条件 key为{条件}_字段    gt_开头大于   ge_开头大于等于   lt开头小于 le_开头小于等于

	private Map<String,Boolean> orderByCondition = new TreeMap<>(); //排序条件 key为字段 value为true为正序  前端传参为 o_顺序(可选)+字段    如 o_priority=T 或  o_0priority=T
	
	private boolean needCount = true;
	
	public QueryPage(boolean needCount) {
		this.needCount = needCount;
	}
	
	public QueryPage(Integer pageSize) {
		this.pageSize = pageSize;
	}
	
	public QueryPage() {
	}



	public boolean isNeedCount() {
		return needCount;
	}

	public void setNeedCount(boolean needCount) {
		this.needCount = needCount;
	}

	public Integer getFirstResult() {
		if(firstResult==null){
			firstResult = (getPage()-1) * pageSize;
		}
		return firstResult;
	}

	public void setFirstResult(Integer firstResult) {
		this.firstResult = firstResult;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		if(page==null||page<1){
			return;
		}
		this.page = page;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		if(pageSize==null||pageSize<1){
			return;
		}
		this.pageSize = pageSize;
	}

	public Map<String, Object> getCondition() {
		return condition;
	}

	public void setCondition(Map<String, Object> condition) {
		this.condition = condition;
	}

	public Map<String, String> getSearchCondition() {
		return searchCondition;
	}

	public void setSearchCondition(Map<String, String> searchCondition) {
		this.searchCondition = searchCondition;
	}

	public Map<String, Object> getRangeCondition() {
		return rangeCondition;
	}

	public void setRangeCondition(Map<String, Object> rangeCondition) {
		this.rangeCondition = rangeCondition;
	}

	public Map<String, Boolean> getOrderByCondition() {
		return orderByCondition;
	}

	public void setOrderByCondition(Map<String, Boolean> orderByCondition) {
		this.orderByCondition = orderByCondition;
	}

}
